package com.c4p.im.httpclient;

import org.springframework.web.reactive.function.client.WebClient;

import java.util.concurrent.ConcurrentHashMap;

public class WebClientCache {
    static final ConcurrentHashMap<String, WebClient> WEBCLIENT_MAP = new ConcurrentHashMap<>();


    public static WebClient getWebClient(String host, String port){
        return getWebClient(host + ":" + port);
    }

    public static WebClient getWebClient(String hostAndPort){
        if (WEBCLIENT_MAP.contains(hostAndPort)){
            return WEBCLIENT_MAP.get(hostAndPort);
        }
        WebClient webClient = WebClient.create("http://" + hostAndPort);
        return WEBCLIENT_MAP.put(hostAndPort, webClient);
    }
}
